Advertisement
x3c2c5

Untitled

Dec 24th, 2022
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.92 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4.  
  5. namespace MilitaryPersonData
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             // Read the data from the file
  12.             string filePath = "military_person_data.txt";
  13.             List<string> lines = File.ReadAllLines(filePath).ToList();
  14.  
  15.             // Initialize a list to store the MilitaryPerson objects
  16.             List<MilitaryPerson> militaryPersons = new List<MilitaryPerson>();
  17.  
  18.             // Process each line of the file
  19.             foreach (string line in lines)
  20.             {
  21.                 // Split the line by the delimiter ";"
  22.                 string[] parts = line.Split(';');
  23.  
  24.                 // Extract the data from the line
  25.                 string lastName = parts[0];
  26.                 string firstName = parts[1];
  27.                 string middleName = parts[2];
  28.                 string zipCode = parts[3];
  29.                 string country = parts[4];
  30.                 string region = parts[5];
  31.                 string district = parts[6];
  32.                 string city = parts[7];
  33.                 string street = parts[8];
  34.                 string house = parts[9];
  35.                 string apartment = parts[10];
  36.                 string nationality = parts[11];
  37.                 string birthYear = parts[12];
  38.                 string birthMonth = parts[13];
  39.                 string birthDate = parts[14];
  40.                 string position = parts[15];
  41.  
  42.                 // Create a MilitaryPerson object with the extracted data
  43.                 MilitaryPerson militaryPerson = new MilitaryPerson(lastName, firstName, middleName, zipCode, country, region, district, city, street, house, apartment, nationality, birthYear, birthMonth, birthDate, position);
  44.  
  45.                 // Add the MilitaryPerson object to the list
  46.                 militaryPersons.Add(militaryPerson);
  47.             }
  48.  
  49.             // You can now process the list of MilitaryPerson objects as needed
  50.             // For example, you could print out their full names and positions:
  51.             foreach (MilitaryPerson militaryPerson in militaryPersons)
  52.             {
  53.                 Console.WriteLine($"{militaryPerson.FirstName} {militaryPerson.MiddleName} {militaryPerson.LastName} ({militaryPerson.Position})");
  54.             }
  55.         }
  56.     }
  57.  
  58.     class MilitaryPerson
  59.     {
  60.         public string LastName { get; set; }
  61.         public string FirstName { get; set; }
  62.         public string MiddleName { get; set; }
  63.         public string ZipCode { get; set; }
  64.         public string Country { get; set; }
  65.         public string Region { get; set; }
  66.         public string District { get; set; }
  67.         public string City { get; set; }
  68.         public string Street { get; set; }
  69.         public string House { get; set; }
  70.         public string Apartment { get; set; }
  71.         public string Nationality { get; set; }
  72.         public string BirthYear { get; set; }
  73.         public string BirthMonth { get; set; }
  74.         public string BirthDate { get; set; }
  75.         public string Position { get; set; }
  76.  
  77.         public MilitaryPerson(string lastName, string firstName, string middleName, string zipCode, string country, string region, string district, string city, string street, string house, string apartment, string nationality, string birthYear, string birthMonth, string birthDate, string position)
  78.         {
  79.             LastName = lastName;
  80.             FirstName = firstName;
  81.             MiddleName = middleName;
  82.             ZipCode = zipCode;
  83.             Country = country;
  84.             Region = region;
  85.             District = district;
  86.             City = city;
  87.             Street = street;
  88.             House = house;
  89.             Apartment = apartment;
  90.             Nationality = nationality;
  91.             BirthYear = birthYear;
  92.             BirthMonth = birthMonth;
  93.             BirthDate = birthDate;
  94.             Position = position;
  95.         }
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement